package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ClientBean;
import com.project.service.IClientService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 客户控制器
 */
@RestController
@RequestMapping("client")
@RequiresPermissions("client:am")
public class ClientController {
    @Autowired
    private IClientService clientService;
    @RequestMapping("cutByItem")
    @RequiresPermissions("client:am")
    public IPage<ClientBean> cutByItem(Integer pageNO, String clientName, String manageRange){
        return clientService.cutByItem(pageNO, clientName, manageRange);
    }


    /**
     * 根据id查询客户信息
     * @param clientId 客户ID
     * @return 客户对象
     */
    @RequestMapping("findClientById")
    @RequiresPermissions("client:am")
    public ClientBean findClientById(Integer clientId){
        return clientService.findClientById(clientId);
    }

    /**
     * 根据客户id修改客户负责人名字和电话号码，经营范围
     * @param clientId 客户id
     * @param name 客户负责人名字
     * @param phone 电话号码
     * @param manageRange 经营范围
     */
    @RequestMapping("updateById")
    @RequiresPermissions("client:am")
    public String updateById(Integer clientId,String name, String phone,String manageRange){
        clientService.updateById(clientId, name, phone, manageRange);
        return "ok";
    }

    /**
     * 添加客户,如果客户名称相同，则不做添加
     * @param client 客户
     */
    @RequestMapping("addClient")
    @RequiresPermissions("client:am")
    public String addClient(ClientBean client){
        clientService.addClient(client);
        return "ok";
    }

    /**
     * 查询所有的客户
     * @return 客户集合
     */
    @RequestMapping("findAllClient")
    @RequiresPermissions("client:am")
    public List<ClientBean> findAllClient(){
        return clientService.findAllClient();
    }
}
